import { ref } from "vue";

export function useColumns(info) {
	const productList = ref([]);
	// if(info.title === '修改') {
	// 	if(info.materialList.length > 0) {
			
	// 		for (let item of info.materialList) {
	// 			item.realNumber = 0
	// 			item.realNumber = item.number
	// 		}
	// 		productList.value = info.materialList
	// 	}
	// }
	if(info.productList && info.productList.length > 0) {
		for (let item of info.productList) {
			item.remarks = ""
			item.realNumber = item.realNumber || item.number
		}
		productList.value = info.productList
	}
	console.log(info.productList)
	const vehicleColumns: TableColumnList = [
		{
			label: "物料编码",
			prop: "material.code",
		},
		{
			label: "物料名",
			prop: "material.name",
		},
		{
			label: "所属仓库",
			prop: "warehouse.name",
			formatter: (row) => {
				return row.warehouse.name + '/'+row.warehouseArea.name + '/'+row.warehouseLocation.name
			},
		},
		{
			label: "账面库存",
			prop: "number",
		},
		{
			label: "实际库存",
			prop: "realNumber",
			slot: "realNumber",
			width: 150
		},
		{
			label: "变化数量",
			prop: "number",
			formatter: (row) => {
				return row.realNumber - row.number
			},
		},
		{
			label: "说明",
			prop: "remarks",
			cellRenderer: ({ row }) => <el-input v-model={row.remarks} type="textarea" placeholder="请输入说明" show-word-limit maxlength="30"/>
		},
		{
			label: "操作",
			fixed: "right",
			width: 80,
			slot: "operation"
		}
	];


	function vehicleOnDel(index) {
		productList.value.splice(index, 1);
	}

	return {
		vehicleColumns,
		productList,
		vehicleOnDel
	};
}
